<?php

/*
 * 分词算法
 */

/**
 * Description of participle
 *
 * @author Administrator
 */
class participle {
    private $CI;
    private $ip;
    private $port;
    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->config('participle',true);
        $this->ip = $this->CI->config->item('participle_ip','participle');
        $this->port = $this->CI->config->item('participle_port','participle');
    }
    /*
     * 获得分词结果
     * @param string text 需要分词的字符串
     * return string
     */
    public function main($text)
    {
        $text = iconv("UTF-8", "GBK//IGNORE", $text);
        $text = urlencode($text);
        $opts = array(
          'http'=>array(
            'method'=>"POST",
            'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
                      "Content-length:".strlen($data)."\r\n" .
                      "Cookie: foo=bar\r\n" .
                      "\r\n",
            'content' => $text,
          )
        );
        $context = stream_context_create($opts);
        $result = file_get_contents($this->ip.$this->port, false, $context);
        $result = iconv("GBK", "UTF-8//IGNORE", $result);
        echo $result;
    }
}